home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 779 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: EU.net!sun4nl!xs4all!usenet
  2. From: martijnl@xs4all.nl (Martijn Lievaart)
  3. Newsgroups: comp.lang.c,comp.lang.c++
  4. Subject: Re: -> How do you use the EXTERN keyword? <-
  5. Date: 7 Jan 1996 01:27:35 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4cn7i7$he7@news.xs4all.nl>
  8. References: <4chkq2$1s06@pulp.ucs.ualberta.ca> <30EC9149.6807@holli.com>
  9. NNTP-Posting-Host: mas01-09.dial.xs4all.nl
  10. X-Newsreader: WinVN 0.99.6
  11.  
  12. In article <30EC9149.6807@holli.com>, gotwals@holli.com says...
  13. >
  14. >Jacob Bukczynski wrote:
  15. >> 
  16. >> I need to use variables in two different source files in the
  17. >> same project. I know that you need to declare them somehow
  18. >> with the EXTERN keyword but I don't know how.
  19. >> 
  20. >> Please help! Reply by email if possible, or just follow-up
  21. >> here. Thanks in advance.
  22. >
  23. >Here is a simple example:
  24. >
  25. >// sample1.cpp
  26. >int globalVar = 123;
  27. >
  28. >// define your function(s) here
  29. >
  30. >// end of file
  31. >
  32. >// sample2.cpp
  33. >extern int globalVar;
  34. >
  35. >// define some more functions here
  36. >
  37. >// end of file
  38. >
  39. >
  40.  
  41. Why not in a header? OK, the linker will catch any errors but it is poor 
  42. style. Next time you work on a C project, this style will come back to haunt 
  43. you.
  44.  
  45. >   I am concerned with the truth.  Reality is of little interest to me.
  46.  
  47. That's obvious now.
  48.  
  49.